{ "cells": [ { "cell_type": "markdown", "id": "5c0bcdfe", "metadata": {}, "source": [ "# Introduction to Python: Basic Concepts for Beginners" ] }, { "cell_type": "markdown", "id": "5e64ee92", "metadata": {}, "source": [ "## Step 1: Displaying Text on the Screen\n", "To make the computer show a message, we use the `print()` function.\n", "The word 'function' means a small command that does a specific task." ] }, { "cell_type": "code", "execution_count": null, "id": "5063a0ba", "metadata": {}, "outputs": [], "source": [ "print(\"Hello, world!\") # This will show the words: Hello, world!" ] }, { "cell_type": "markdown", "id": "204326a4", "metadata": {}, "source": [ "## Step 2: Displaying Numbers\n", "We can also show numbers on the screen:" ] }, { "cell_type": "code", "execution_count": null, "id": "220c0c08", "metadata": {}, "outputs": [], "source": [ "print(123) # This will show the number: 123" ] }, { "cell_type": "markdown", "id": "034bc979", "metadata": {}, "source": [ "## Step 3: Combining Text and Information\n", "We can show both text and information like names or numbers together." ] }, { "cell_type": "code", "execution_count": null, "id": "0deb649b", "metadata": {}, "outputs": [], "source": [ "name = \"Ana\" # We are saving the name 'Ana' in a box called 'name'\n", "age = 25 # We are saving the number 25 in a box called 'age'\n", "\n", "# Method 1: Using commas to combine them\n", "print(\"Hello, my name is\", name, \"and I am\", age, \"years old.\")\n", "\n", "# Method 2: Using the + sign (we need to convert numbers to text)\n", "print(\"Hello, my name is \" + name + \" and I am \" + str(age) + \" years old.\")" ] }, { "cell_type": "markdown", "id": "31098930", "metadata": {}, "source": [ "## Step 4: Getting User Input\n", "To ask the user to type something, we use the `input()` function." ] }, { "cell_type": "code", "execution_count": null, "id": "aeba899b", "metadata": {}, "outputs": [], "source": [ "user_name = input(\"Enter your name: \") # This asks for the user's name\n", "print(\"Hello,\", user_name, \"!\") # Shows a greeting with the name" ] }, { "cell_type": "markdown", "id": "f82ce808", "metadata": {}, "source": [ "## Step 5: Input as Text\n", "Important: Whatever the user types is saved as text (even if it's a number)." ] }, { "cell_type": "code", "execution_count": null, "id": "f9b2b66b", "metadata": {}, "outputs": [], "source": [ "user_age = input(\"Enter your age: \") # The user types their age\n", "print(\"Your age is:\", user_age) # Shows the age (but it's still text)" ] }, { "cell_type": "markdown", "id": "14b59956", "metadata": {}, "source": [ "## Step 6: Converting Text to Numbers\n", "If we want to do math with the age, we need to turn the text into a number." ] }, { "cell_type": "code", "execution_count": null, "id": "3081aebe", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "In 5 years you will be 11 years old.\n" ] } ], "source": [ "user_age = int(input(\"Enter your age (number): \")) # int() changes text to a number\n", "print(\"In 5 years you will be\", user_age + 5, \"years old.\") # Now we can add numbers" ] }, { "cell_type": "markdown", "id": "278cc3db", "metadata": {}, "source": [ "## Step 7: Comments in Python\n", "Anything after a `#` is a comment. Comments are for humans to understand the code.\n", "The computer ignores comments when running the code." ] }, { "cell_type": "markdown", "id": "23f1e172", "metadata": {}, "source": [ "## Step 8: Practical Exercises\n", "Now, it's your turn! Here are some exercises to practice." ] }, { "cell_type": "markdown", "id": "exercise1", "metadata": {}, "source": [ "### Exercise 1: Name Greeting\n", "Write a program that asks for the user's name and prints a personalized greeting.\n", "For example:\n", "```\n", "Enter your name: John\n", "Hello, John!\n", "```" ] }, { "cell_type": "markdown", "id": "exercise2", "metadata": {}, "source": [ "### Exercise 2: Full Name\n", "Write a program that asks for the user's first name and last name and prints their full name." ] }, { "cell_type": "markdown", "id": "exercise3", "metadata": {}, "source": [ "### Exercise 3: Favorite Color\n", "Write a program that asks for the user's favorite color and prints a message like:\n", "```\n", "Your favorite color is blue!\n", "```" ] }, { "cell_type": "markdown", "id": "exercise4", "metadata": {}, "source": [ "### Exercise 4: Hobby Introduction\n", "Write a program that asks for the user's favorite hobby and prints a message like:\n", "```\n", "Your favorite hobby is painting!\n", "```" ] }, { "cell_type": "markdown", "id": "exercise5", "metadata": {}, "source": [ "### Exercise 5: City Introduction\n", "Write a program that asks for the user's city and prints a message like:\n", "```\n", "You live in Madrid!\n", "```" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": {}, "name": "python", "version": "3.11.3" } }, "nbformat": 4, "nbformat_minor": 2 }